package com.chenzhou.product_sys.controller;

import com.chenzhou.product_sys.entity.GoodsTypeEntity;
import com.chenzhou.product_sys.entity.Product;
import com.chenzhou.product_sys.service.GoodsTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/goods_type")
public class GoodsTypeController {

    @Autowired
    private GoodsTypeService service;

    @RequestMapping("/query_goodsType")
    public String show_GoodsTypes(HttpServletRequest request){
        ///TODO 商品类别信息的查询
        List<GoodsTypeEntity> list = service.queryAllGoodsType();
        request.setAttribute("gtlist",list);
        request.setAttribute("menu","goods_type");
        return "goods_type/show_goodsType";
    }

    @RequestMapping("/get_goodsTypeOne")
    public String  queryGoodsTypeOne(HttpServletRequest request,Integer id){
        GoodsTypeEntity goodsType = service.queryGoodsTypeById(id);
        request.setAttribute("goodsType",goodsType);
        request.setAttribute("menu","goods_type");
        return "goods_type/modify_goodsType";
    }

    @RequestMapping("/add_goodsType")
    public String add_GoodsType(HttpServletRequest request, GoodsTypeEntity goodsType){
        int a = service.add_GoodsType(goodsType);
        if(a>0){
            return  "redirect:/goods_type/query_goodsType";//防止重复提交
        }else{
            return "forward:/error.jsp";
        }
    }

    @RequestMapping("/modify_goodsType")
    public String modify_GoodsType(HttpServletRequest request,  GoodsTypeEntity goodsType){
        int a = service.modify_GoodsType(goodsType);
        if(a>0){
            return  "redirect:/goods_type/query_goodsType"; //防止重复提交
        }else{
            return "forward:/error.jsp";
        }
    }

    @RequestMapping("/delete_goodsType")
    public String delete_GoodsType(HttpServletRequest request, Integer id){
        int a = service.delete_GoodsType(id);
        if(a>0){
            return  "forward:/goods_type/query_goodsType"; //防止重复提交
        }else{
            return "forward:/error.jsp";
        }
    }
}
